package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.community.model.Organization;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.member.model.Member;
import com.eling.elcms.privilege.service.impl.CommonPrivilegeCriteriaEnhancer;
import com.eling.elcms.system.model.CommonUser;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;
/**
 * 邮寄登记
 * @author zhangkailun
 * 
 * 模型评审：新增模型，wulina 2016-09-07
 *
 */
@Entity
@Table(name = "travel_mail")
@Indexed
@CriteriaEnhancers(criteriaEnhancers = { @CriteriaEnhancer(impl = CommonPrivilegeCriteriaEnhancer.class, parameter = "organization:organization") })
public class Mail extends BaseModel{

	private static final long serialVersionUID = -4136498542418903722L;

	/** 主键*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	@In
	private Long pkMail;
	
	/** 登记机构*/
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOrganization")
    @IndexedEmbedded(depth = 1)
	private Organization organization;
	
	/** 所属计划*/
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkPlan")
    @IndexedEmbedded(depth = 1)
	private Plan plan;
	
	/** 产品*/
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkProduct")
    @IndexedEmbedded(depth = 1)
	private Product product;
	
	/** 对应会员*/
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkMember")
	@IndexedEmbedded(depth = 1)
	private Member member;
	
	/** 邮寄方式*/
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	@In
	private MailMethod mailMethod;
	
	/** 经办人*/
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkCommonUser")
	@IndexedEmbedded(depth = 1)
	private CommonUser commonUser;
	
	/** 邮寄日期*/
	@Column
	@Field
	private Date mailTime;
	
	@Version
	private Integer version;
	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum MailMethod {
		OrdinaryMail("平信"),
		Express("快递"),
		Ems("EMS");
		
		private String display;

		MailMethod(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Long getPkMail() {
		return pkMail;
	}

	public void setPkMail(Long pkMail) {
		this.pkMail = pkMail;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	public Plan getPlan() {
		return plan;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public void setPlan(Plan plan) {
		this.plan = plan;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public MailMethod getMailMethod() {
		return mailMethod;
	}

	public void setMailMethod(MailMethod mailMethod) {
		this.mailMethod = mailMethod;
	}

	public CommonUser getCommonUser() {
		return commonUser;
	}

	public void setCommonUser(CommonUser commonUser) {
		this.commonUser = commonUser;
	}

	public Date getMailTime() {
		return mailTime;
	}

	public void setMailTime(Date mailTime) {
		this.mailTime = mailTime;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}			

}
